<html>

	<head>
		<meta charset="UTF-8">
		<title>站点列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<!--<link rel="stylesheet" href="../../layui/css/dtree.css" />-->
		<link rel="stylesheet" href="../../layui/css/font/iconfont.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
		<style type="text/css">
			.dtree-menubar .layui-btn-group .layui-btn-sm {
				width: 50px;
				height: 30px;
				background-color: #009688;
				color: #fff;
				border: none;
				border-radius: 2px;
				margin-right: 10px !important;
			}
			
			.dtree-menubar .layui-btn-group .layui-btn-sm i {
				font-size: 16px !important;
			}
		</style>
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">
				<p class="content_title">站点管理 &nbsp;&nbsp;>&nbsp;&nbsp;站点列表</p>
				<div class="content_seach">
					<div class="content_seach">
						<div class="layui-form">
							<div class="layui-inline">
								<label class="layui-form-label">站点名称</label>
								<div class="layui-input-inline">
									<input type="text" class="layui-input" name="siteName" placeholder="请输入站点名称">
								</div>
							</div>
							<div class="layui-btn layui-btn-warm search layui-btn-sm" id="search" lay-submit="" lay-filter="search">
								<i class="layui-icon">&#xe615;</i>查询
							</div>
						</div>
					</div>
				</div>
				<div class="content_table" style="margin-top: 20px;">
					<script type="text/html" id="toolbarDemo">
  						<div class="layui-btn-container">
  							<button class="layui-btn layui-btn-sm" lay-event="addCheckData"><i class="layui-icon">&#xe654;</i> 添加</button>
    						<button class="layui-btn layui-btn-sm" lay-event="delCheckData"><i class="layui-icon">&#xe640;</i>删除</button>
  						</div>
					</script>
					<div class="tabTable">
						<table id="demo" lay-filter="table" lay-data="{id:'idTest'}"></table>
						<div class="layui-table-page fr">
							<div id="layui-table-page1"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="maTypeTemplet">
			{{#if (d.siteType == 0) { }}
			门店
			{{# }else if(d.siteType == 1){ }}
			调压站
			{{# }else if(d.siteType == 2){ }}
			LNG站
			{{# }else if(d.siteType == 3){ }}
			电厂
			{{# }else if(d.siteType == 4){ }}
			直供用户
			{{# } }}
		</script>
		<script type="text/html" id="transTemplet">
			{{#if (d.transportType == 1) { }}
			天然气管线
			{{# } }}
		</script>
		<script type="text/html" id="barContractUpdate">
			<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
		</script>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script>
			layui.use(['table','form','layer'], function (){
				var table = layui.table;
				var form = layui.form;
				ajaxTable({
					idNode: '#demo',
					url: 'site/getList',
					dataCols: [
						{fixed: true, checkbox: true},
						{field: 'siteName', title: '站点名称',align: 'center'},
						{field: 'siteType', title: '站点类型',align: 'center',templet:'#maTypeTemplet',},
						{field: ' transportType', title: '运输类型',align: 'center',templet:function(d){
							if(d.transportType == 1){
								return '<div>天然气管线</div>';
							}
						}},
						{field: 'daySource', title: '日气量来源',align: 'center',templet:function(d){
							if(d.daySource == 1){
								return '<div>占仪表日计量数据</div>';
							}
						}},
						{field: 'dayDeviation', title: '计量日偏移',align: 'center'},
						{field: 'timeIntervalPoint', title: '时段分割点',align: 'center'},
						{field: 'siteDesc', title: '备注',align: 'center'},
						{field: 'right', title: '操作', width: 170, toolbar: "#barContractUpdate"}
					],
					successFull:function(res, curr, count,table){
						console.log(res)
						table.on('toolbar(table)', function(obj) {
							var checkStatus = table.checkStatus(obj.config.id);
							var data = checkStatus.data;
							if (obj.event == 'addCheckData') {
									window.location.href = './siteAdd.html?pos=1&childPos=0'
								} else if(obj.event == 'editCheckData') {
										var data = checkStatus.data;
										if (data.length == '') {
											layer.msg('请勾选要修改的站点', {
												icon: 6
											});
										}else if(data.length>1){
											layer.msg('一次最多只能修改一个用户', {
												icon: 6
											});
										}else{
											var data = checkStatus.data;
											console.log(data)
											window.location.href = './siteEdit.html?pos=1&childPos=0&id='+data[0].id;
										}
							};
							if(obj.event == 'delCheckData'){
//                        console.log(111)
								var data = checkStatus.data;
								if(data.length<=0){
									layer.msg('请勾选要删除的站点', {
										icon: 6
									});
								}else{
									layer.confirm('确定删除吗？', function (index) {
										console.log(data);
										var ids = [];
										$.each(data,function(i,item){
											ids.push(item.id)
										});
										$.ajax({
											url: baseUrl + "site/batchDel",
											type: "POST",
											data:{
												ids:ids
											},
											dataType: "json",
											success: function (data) {
												if (data.code == 200) {
													layer.close(index);
													layer.msg("删除成功", {icon: 6});
													updata()
												} else {
													layer.msg("删除失败", {icon: 5});
												}
											}
										});
									});
								}
							}
						})
					}
				});

				//        条件查询
				form.on('submit(search)', function(data){
//            data.field.devicename = !data.field.devicename?"":data.field.devicename;
					var user =  JSON.parse(window.sessionStorage.getItem('user'));
					var companyName = !user.msg.userCompanyAllTitle ? "": '&userCompanyAllTitle='+user.msg.userCompanyAllTitle+'&startTime='+data.field.startTime+'&endTime='+data.field.endTime+'&status='+data.field.status;
					ajaxTable({
						idNode: '#demo',
						url: 'site/getList',
						urlParme:'&siteName='+data.field.siteName,
						dataCols: [
							{fixed: true, checkbox: true},
							{field: 'siteName', title: '站点名称',align: 'center'},
							{field: 'siteType', title: '站点类型',align: 'center',templet:'#maTypeTemplet',},
							{field: ' transportType', title: '运输类型',align: 'center'},
							{field: 'daySource', title: '日气量来源',align: 'center'},
							{field: 'dayDeviation', title: '计量日偏移',align: 'center'},
							{field: 'timeIntervalPoint', title: '时段分割点',align: 'center',},
							{field: 'siteLongitude', title: '站点经度',align: 'center'},
							{field: 'siteLatitude', title: '站点纬度',align: 'center'},
							{field: 'siteDesc', title: '备注',align: 'center'},
							{field: 'right', title: '操作', width: 170, toolbar: "#barContractUpdate"}
//                    {field: 'right', title: '操作', width: 170, toolbar: "#barContractUpdate"}
						],
						successFull: function (res, curr, count,table) {

						}
					});
				});
				table.on('tool(table)', function (obj) {
					var data = obj.data;
					if (obj.event === 'detail') {
						layer.msg('ID：' + data.id + ' 的查看操作');
					} else if (obj.event === 'del') {
						layer.confirm('确定删除吗？', function (index) {
							console.log(data);
							$.ajax({
								url: baseUrl + "site/del",
								type: "POST",
								data: {"id": data.id},
								dataType: "json",
								success: function (data) {
									if (data.code == 200) {
										obj.del();
										layer.close(index);
										layer.msg("删除成功", {icon: 6});
										updata();
									} else {
										layer.msg("删除失败", {icon: 5});
									}
								}
							});
						});
					} else if (obj.event === 'edit') {
						layer.confirm('确定修改吗？', function (index) {
							window.location.href = './siteEdit.html?pos=1&childPos=0&id='+data.id;
						});
					}
				});
			});

			function updata(){
        		ajaxTable({
           			idNode: '#demo',
            		url: 'site/getList',
            		dataCols: [
               			{fixed: true, checkbox: true},
                		{field: 'siteName', title: '站点名称',align: 'center'},
                		{field: 'siteType', title: '站点类型',align: 'center',templet:'#maTypeTemplet',},
                		{field: ' transportType', title: '运输类型',align: 'center'},
                		{field: 'daySource', title: '日气量来源',align: 'center'},
                		{field: 'dayDeviation', title: '计量日偏移',align: 'center'},
                		{field: 'timeIntervalPoint', title: '时段分割点',align: 'center',},
                		{field: 'siteLongitude', title: '站点经度',align: 'center'},
                		{field: 'siteLatitude', title: '站点纬度',align: 'center'},
                		{field: 'siteDesc', title: '备注',align: 'center'},
						{field: 'right', title: '操作', width: 170, toolbar: "#barContractUpdate"}
            		]
        		})
    		}
		</script>
	</body>

</html>